/*
 * Filename:    CodeListServiceImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月17日
 */
package com.paic.mhis.hcpms.common.community.biz.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.paic.mhis.common.base.dto.LabelDTO;
import com.paic.mhis.common.base.intergration.dao.CommonDAO;
import com.paic.mhis.hcpms.agreement.healthcareprovider.util.HealthCareConstants;
import com.paic.mhis.hcpms.common.community.biz.service.CommunityService;
import com.paic.mhis.hcpms.common.community.dto.CodeListDTO;
import com.paic.mhis.hcpms.common.community.dto.HcpmsContactInfoDTO;
import com.paic.mhis.hcpms.common.community.dto.MedicalDeptDTO;
import com.paic.mhis.hcpms.common.community.dto.MedicalOrgInfoDTO;
import com.paic.mhis.hcpms.common.community.dto.MedicalProviderReleDTO;
import com.paic.mhis.hcpms.common.community.intergration.dao.CommunityDAO;

@Component("communityService")
public class CommunityServiceImpl implements CommunityService {

	@Autowired
	public CommunityDAO communityDao;

	@Autowired
	private CommonDAO commonDAO;

	@Override
	public List<CodeListDTO> getCodeListDatas() {
		return communityDao.queryCodeListAll();
	}
	
	@Override
	public List<CodeListDTO> getCodeListDatas(Map<String, Object> map) {
		return communityDao.queryCodeList(map);
	}

	@Override
	public List<MedicalOrgInfoDTO> getMedicalOrgInfoList(Map<String, Object> map) {
		return communityDao.queryMedicalOrgInfoList(map);
	}

	@Override
	public List<MedicalDeptDTO> getMedicalDeptInfoList(Map<String, Object> map) {
		return communityDao.queryMedicalDeptInfoList(map);
	}

	@Override
	public List<MedicalOrgInfoDTO> getNewMedicalOrgInfoList(Map<String, Object> paramMap) {
		String userName = (String) paramMap.get("userName");
		List<Map<String, String>> userTypeList = (List<Map<String, String>>) commonDAO.query("getUserType", userName);
		String userType = "";
		String orgCode = "";
		if (null != userTypeList) {
			for (int i = 0; i < userTypeList.size(); i++) {
				Map<String, String> tempMap = userTypeList.get(i);
				userType = (String) tempMap.get("accountType");
				orgCode = orgCode + "'" + (String) tempMap.get("orgCode") + "',";
			}
		}
		// 医院类型账户
		if (HealthCareConstants.USER_HOSPITAL.equals(userType)) {
			orgCode = orgCode.substring(0, orgCode.length() - 1);
			paramMap.put("orgCode", orgCode);
		}
		return communityDao.queryNewMedicalOrgInfoList(paramMap);
	}

	@Override
	public List<HcpmsContactInfoDTO> getWorkDepList(Map<String, Object> paramMap) {
		return communityDao.queryWorkDepList(paramMap);
	}

	@Override
	public List<MedicalProviderReleDTO> queryProvincialInfoByHosCode(Map<String, Object> paramMap) {
		return (List<MedicalProviderReleDTO>) commonDAO.query("healthcare.queryProvincialInfoByHosCode", paramMap);
	}

	@Override
	public Object getMedicalOrgInfoListWithLevel(Map<String, Object> paramMap) {
		return communityDao.queryMedicalOrgInfoListWithLevel(paramMap);
	}

	public List<CodeListDTO> getProvincialOrgDepList(Map<String, Object> paramMap) {
		return communityDao.getProvincialOrgDepList(paramMap);
	}

	public List<LabelDTO<String>> getAllSex(Map<String, Object> paramMap) {
		return communityDao.getAllFiledDict(paramMap);
	}

	@Override
	public List<LabelDTO<String>> getAllFiledDict(Map<String, Object> param) {

		return communityDao.getAllFiledDict(param);
	}
}
